package com.example.weatherjavaui.slice;

import com.example.weatherjavaui.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {

    private static Button button_edit;
    private static Button button_add;

    private final static String BundleName = "com.example.weatherjavaui";


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        BtnSst();
    }
    private void BtnSst() {
        button_edit = (Button) findComponentById(ResourceTable.Id_button_edit_main);
        button_add = (Button) findComponentById(ResourceTable.Id_button_add_mian);

        button_edit.setClickedListener(component -> JumpSlice("com.example.weatherjavaui.ResourceAbility"));

        button_add.setClickedListener(component -> JumpSlice("com.example.weatherjavaui.WeatherAbility"));
    }

    private void JumpSlice(String abilityName) {
        Intent it = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(BundleName)
                .withAbilityName(abilityName)
                .build();
        it.setOperation(operation);
        startAbility(it);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
